var RM008 = {};

RM008.init = function() {
    
    _COMBOBOX.StatusCombo('active');
    _COMBOBOX.PriorityCombo('priority');
    
    _COMBOBOX.TowerFloorUnitAddrCombo('tower', 'floor' , 'unit' , 'address','roomId');

};

RM008.clearHeaderCriteria = function(){

   $('#docNo').clear();
   $('#active').clear();
   $('#priority').clear();
  
  _COMBOBOX.ResetAllTowerCriteria('tower', 'floor' , 'unit' , 'address','roomId');

};



RM008.loadDataTable = function(isSearch) {
    
    $('#dataTable')
    .dataTable(
	    {
		bDestroy : true,
		bProcessing : false,
		bServerSide : true, 
		bLengthChange : false,
		bFilter : false,
//		"bJQueryUI": true,
		sCharSet : "utf-8",
		sAjaxSource : "getRequestDataTable",
		fnServerParams : function(aoData) {
		    // --- for search params
		    aoData.push({
			"name" : "model.sreqhdocno",
			"value" : $('#docNo').val()
		    }, {
			"name" : "model.sreqhstat",
			"value" : $('#active').val()
		    }, {
			"name" : "model.sreqhprt",
			"value" :$('#priority').val()
		    }, {
			"name" : "model.towerModel.tower",
			"value" :$('#tower').val()
		    }, {
			"name" : "model.towerModel.floor",
			"value" :$('#floor').val()
		    }, {
			"name" : "model.towerModel.unitNo",
			"value" : $('#unitNo').val()
		    },{
			"name" : "model.towerModel.address",
			"value" : $('#address').val()
		    });
		},
		columns : [ {
		    "data" : "sreqhid",
		    "sClass" : "center"
		}, {
		    "data" : "sreqhdocno"
		}, {
		    "data" : "sreqhstat"
		}, {
		    "data" : "sreqhprt"
		}, {
		    "data" : "towerModel.tower"
		}, {
		    "data" : "towerModel.floor"
		}, {
		    "data" : "towerModel.unitNo",
		    "sClass" : "center"
		},{
		    "data" : "towerModel.address",
		    "sClass" : "center"
		} ],
		aaSorting: [[1, 'asc']],
		columnDefs : [
//			{
//			    render : function(data, type, row) {
//				var rol = [];
//				$.each(data, function(a) {
//				    rol.push(data[a].roleName);
//				});
//				return rol.join();
//			    },
//			   targets : 5
//			},
//			{
//			    render : function(data, type, row) {
//				 return  _COMMON.StatusRender[data];
//			    },
//			    targets : 6
//			},
	                   {
	                      render: function ( data, type, row ) {
	                	   return  _COMMON.ButtonRender.editBtn('RM008.editBysSeqhid(\''+data+'\')' ,  _COMMON.isUserHide) + '&nbsp;'+
	                	   	_COMMON.ButtonRender.delBtn('RM008.onSreqhidDelete(\''+data+'\')',  _COMMON.isUserHide);
	                       },
	                       targets: 0
	                   },
	                   { 'bSortable': false, 'aTargets': [ 0 ] }
	               ],
    });

};
RM008.editBysSeqhid = function(data){
	location = 'RM008Aedit?sreqhid='+data;
};
RM008.onSreqhidDelete = function(data){

    $("#confirm").html("Do you want to delete ?");

    $("#confirm").dialog({
        resizable: false,
        modal: true,
        title: "Confirm Delete",
        height: 180,
        width: 300,
        buttons: {
            "Yes": function () {
                $(this).dialog('close');
                location = 'RM008ADelete?sreqhid='+data;
            },
                "No": function () {
                $(this).dialog('close');
            }
        }
    });
};

$(document).ready(function() {
    
    _log(' ######## --- RM008 -------######');
    
    RM008.init();
    RM008.loadDataTable();
    $("#btnSearch").click(function() {
    	 RM008.loadDataTable();
    });
    $("#btnClear").click(function() {
	RM008.clearHeaderCriteria();
    });
    
});
